//
//  HMVisitorView.swift
//  CZBKWB31
//
//  Created by Linkon Y on 16/8/9.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import SnapKit

class HMVisitorView: UIView {

    //声明一个闭包1
    var closure:(() -> ())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // MARK: - 监听方法
    func loginClick(){
     //执行闭包03
        closure?()

    }

     // MARK: - 外界调用的方法
    
    func setupVisitorViewInfo(imageName: String? , title: String? ){
    
        if let img =  imageName , til = title {
            
            iconImageView.image = UIImage(named: img)
            
            messageLabel.text = til
            
            circleImageView.hidden = true
            
        }else{
            //首页
            setupAnim()
        
        }

    }
    
     // MARK: - 设置动画
    func setupAnim(){
       
        let anim = CABasicAnimation(keyPath:"transform.rotation")
    
       anim.toValue = M_PI * 2
       anim.duration = 10
       anim.repeatCount = MAXFLOAT
       anim.removedOnCompletion = false
        circleImageView.layer.addAnimation(anim, forKey: nil)
    
    }
    
     // MARK: - 设置视图
    private func setupUI(){
    
      backgroundColor = RGB(237, green: 237, blue: 237)
        //添加控件
        addSubview(circleImageView)
        addSubview(maskImageView)
        addSubview(iconImageView)
        addSubview(messageLabel)
        addSubview(registerBtn)
        addSubview(loginBtn)
        //添加约束
        //圆圈
        circleImageView.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        //遮挡
        maskImageView.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        //房子
        iconImageView.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        //lab
        messageLabel.snp_makeConstraints { (make) in
            make.top.equalTo(maskImageView.snp_bottom).offset(15)
            make.height.equalTo(36)
            make.centerX.equalTo(self)
        }
        //注册
        registerBtn.snp_makeConstraints { (make) in
            make.top.equalTo(messageLabel.snp_bottom).offset(10)
            make.leading.equalTo(messageLabel)
            make.size.equalTo(CGSize(width: 100, height: 36))
        }
    
        //登录
        loginBtn.snp_makeConstraints { (make) in
            make.size.top.equalTo(registerBtn)
            make.trailing.equalTo(messageLabel)
        }
        
        
    }
 
    
    // MARK: - 添加控件
    //圆圈
    private lazy var circleImageView: UIImageView = UIImageView(imageName: "visitordiscover_feed_image_smallicon")
    //遮挡
    private lazy var maskImageView: UIImageView = UIImageView(imageName: "visitordiscover_feed_mask_smallicon")
    //房子
    private lazy var iconImageView: UIImageView = UIImageView(imageName: "visitordiscover_feed_image_house")
    //文字
    private lazy var messageLabel: UILabel = {
        
        let lab = UILabel()
        lab.textColor = AppThemeColor
        lab.font = UIFont.systemFontOfSize(12)
        lab.numberOfLines = 0
        lab.textAlignment = .Center
        lab.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        //设置LAB 最大显示宽度
        lab.preferredMaxLayoutWidth = 240
        
        return lab
    }()

    //注册按钮
    private lazy var registerBtn: UIButton = {
        let btn = UIButton()
        btn.addTarget(self, action: "loginClick", forControlEvents: UIControlEvents.TouchUpInside)
        btn.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: UIControlState.Normal)
        btn.setTitle("注册", forState: UIControlState.Normal)
        btn.setTitleColor(AppThemeColor, forState:UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(12)
    
    return btn
    }()
    
    //登录按钮

    private lazy var loginBtn: UIButton = {
        let btn = UIButton()
        btn.addTarget(self, action: "loginClick", forControlEvents: UIControlEvents.TouchUpInside)
        btn.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: UIControlState.Normal)
        btn.setTitle("登录", forState: UIControlState.Normal)
        btn.setTitleColor(AppThemeColor, forState:UIControlState.Normal)
         btn.titleLabel?.font = UIFont.systemFontOfSize(12)
        return btn
        
    }()


    
    
    



}